import request from '@/utils/request'
/**
 * 获取优惠券管理列表
 * @param {*} params
 * @returns
 */
export function getCouponList(data) {
  return request({
    url: '/api/app/coupon/get-all',
    method: 'post',
    baseURL: public_config.labor_api,
    data,
  })
}

/**
 * 按ID查询优惠券
 * @param {*} id
 * @returns
 */
export function getByIdCouponList(id) {
  return request({
    url: `/api/app/coupon/${id}`,
    method: 'get',
    baseURL: public_config.labor_api,
  })
}

export function deleteCouponList(data) {
  let json = ``
  data.forEach((item, index) => {
    console.log(item)
    if (index == 0) {
      json = `?ids=${item.id}`
    } else if (index > 0) {
      json += `&ids=${item.id}`
    }
  })
  return request({
    url: '/api/app/coupon/' + json,
    method: 'delete',
    baseURL: public_config.labor_api,
  })
}

export function insertCouponList(data) {
  return request({
    url: '/api/app/coupon/do-add',
    method: 'post',
    baseURL: public_config.labor_api,
    data,
  })
}

export function updateCouponList(data) {
  return request({
    url: '/api/app/coupon/do-update',
    method: 'post',
    baseURL: public_config.labor_api,
    data,
  })
}

export function provudeById(id) {
  return request({
    url: `/api/app/coupon/provide/${id}`,
    method: 'post',
    baseURL: public_config.labor_api,
  })
}

export function GetCouponListExcel(params) {
  return request({
    url: '/api/Export/GetExcelCouponMaterialList',
    method: 'get',
    baseURL: public_config.labor_api,
    responseType: 'blob',
    params,
  })
}

export function GetCouponExcel(params) {
  return request({
    url: '/api/Export/GetExcelCouponList',
    method: 'get',
    baseURL: public_config.labor_api,
    responseType: 'blob',
    params,
  })
}

export function importCoupon(data) {
  return request({
    url: `/api/app/coupon/import-material`,
    method: 'post',
    baseURL: public_config.labor_api,
    data,
  })
}

export function importCouponList(data) {
  return request({
    url: `/api/app/coupon/import`,
    method: 'post',
    baseURL: public_config.labor_api,
    data,
  })
}

export function importCouponSave(data) {
  return request({
    url: `/api/app/coupon/save-import`,
    method: 'post',
    baseURL: public_config.labor_api,
    data,
  })
}

export function queryMaterial(params) {
  return request({
    url: `/api/app/coupon/query-material`,
    method: 'get',
    baseURL: public_config.labor_api,
    params,
  })
}
